﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

public partial class Controls_Dangnhap : System.Web.UI.UserControl
{
    BUS_Customers customer = new BUS_Customers();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["UserName"] != null)
        {
            Response.Redirect("Trangchu.aspx");
        }
    }
    protected void btnDangnhap_Click(object sender, EventArgs e)
    {
        string User = txtUsre.Text;
        string Pass = FormsAuthentication.HashPasswordForStoringInConfigFile(txtPassword.Text, "MD5");
        var dt = customer.Customers_GetByTop(0, "UserName = '" + User+"' and PassWord = '"+Pass+"'", "");
        if (dt.Rows.Count >0)
        {
            
            Session["UserName"] = User;
            Session["FullName"] = dt.Rows[0]["FullName"].ToString();
            Session["UserName_ID"] = dt.Rows[0]["Id"].ToString();
            if (Session["GioHang"] != null)
            {
                Response.Redirect("Giohang.aspx");
            }
            else
            {
                Response.Redirect("Trangchu.aspx");
            }
        }
        //Response.Write(Pass);
    }
}